package top.carrotguo.divide;

/**
 * 二分递归求和
 * @Author: Carrot
 * @Mail: 1053155183carrot@gmail.com
 * @Date: Created in 20:04 2018-05-13
 */
public class BinaryRecursive {

    public int sum (int[] A, int lo, int hi) {
        if (lo == hi) {
            return A[lo];
        }
        int min = (lo+hi)/2;
        return sum(A,lo,min)+sum(A,min+1,hi);
    }

    public static void main (String[] args) {
        BinaryRecursive binaryRecursive = new BinaryRecursive();
        int sum = binaryRecursive.sum(new int[]{2,5,5,8,9,7},0,5);
        System.out.print("sum="+sum);
    }

}
